package edu.hunis.service.impl;

import edu.hunis.exception.SSMServicesException;
import edu.hunis.mapper.UserMapper;
import edu.hunis.pojo.User;
import edu.hunis.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

@Service  //表明为业务层
public class UserServiceImpl implements UserService {
    // DI 依赖注入   IoC
    @Resource
    private UserMapper userMapper;

    @Override
    public User queryById(Integer id) {
        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    public User login(String telphone, String pwd) {
        User user = userMapper.queryByTelphoneAndPwd(telphone, pwd);
        if(Objects.isNull(user)){
            throw new SSMServicesException("用户名或者密码错误！");
        }
        return user;
    }
}
